<?php
/*
    Copyright (C) 2008 - 2010 Inanta Martsanto
    
    This file is part of Koma.

    Koma is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Koma is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Koma.  If not, see <http://www.gnu.org/licenses/>.
    
    Inanta Martsanto (inanta@inationsoft.com)
*/

class KomaWidgetLanguageMenu extends KomaWidget
{
	function __construct($cssclass = 'koma-LanguageMenu')
	{
		if(strpos($_SERVER['REQUEST_URI'], '?') === false)
		{
			$last_url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'?';
		}
		else
		{
			if(isset($_GET['locale']))
			{
				$last_url = str_replace('locale='.$_GET['locale'], '', 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
			}
			else
			{
				$last_url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'&';
			}
		}
	
		$widget ='<div class="'.$cssclass.'"><ul>';
		
		foreach(KomaLists::getInstalledLocales() as $id => $locale)
		{
			$widget .= '<li><a href="'.$last_url.'locale='.$id.'">'.$locale.'</a></li>';
		}
		
		$widget .= '</ul></div>';
		
		parent::__construct($widget);
	}
}
?>